<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #canvas {
            border: 1px solid black;
        }
    </style>
</head>
<body>
<canvas width="600px" height="300px" id="canvas"></canvas>
<script>
    const canvas = document.querySelector("#canvas")
    const ctx = canvas.getContext("2d")
    ctx.moveTo(300, 50)
    ctx.lineTo(520, 230)
    ctx.lineTo(130, 230)
    //   ctx.lineTo(300, 50)
    // 自动闭合最后一条路径
    ctx.closePath()
    ctx.strokeStyle = '#bcbcbc'
    ctx.lineWidth = 3
    ctx.stroke()
</script>
</body>
</html>